<h2>Danh sách giảm giá</h2>

<a class="custom" href="?action=add">Thêm</a><a class="custom" href="javascript: history.go(-1);" >Trở lại</a>
<table class="employees" border="0">
    <tr>
        <th><input type="checkbox" name="" id="checkAll" onclick="checkAll();" value="" /></th>
        <th>ID</th>
        <th>Pro id</th>
        <th>Date Start</th>
        <th>Date End</th>
        <th>Content</th>
        <th>Percent Decrease</th>
        <th>Action</th>
    </tr>
    <?php
    $sale = new Admin_Models_Sale();
    foreach ($this->proSale as $sale) {
        ?>
        <tr class="emp">
            <td class="cell"><input type="checkbox" name="checkOne[]" value="<?php echo $sale->getSaleId(); ?>" /></td>
            <td class="cell"><?php echo $sale->getSaleId(); ?></td>
            <td class="cell"><?php echo $sale->getProId(); ?></td>
            <td class="cell"><?php echo date("d/m/Y", strtotime($sale->getDateStart())); ?></td>
            <td class="cell"><?php echo date("d/m/Y", strtotime($sale->getDateEnd())); ?></td>
            <td class="cell"><?php echo $sale->getContent(); ?></td>
            <td class="cell"><?php echo $sale->getPercentDecrease() . '%'; ?></td>
            <td class="cell"><a href="<?php echo "?action=edit&sale_id={$sale->getSaleId()}&ds={$sale->getDateStart()}&de={$sale->getDateEnd()}&content={$sale->getContent()}&pd={$sale->getPercentDecrease()}"; ?>">Sửa</a> / <a href="<?php echo URL_BASE . '/admin/product/delSale/' . $sale->getSaleId() . '?pro_id=' . $sale->getProId(); ?>" onclick="if (confirm('Bạn có chắc chắn muốn xóa không?'))
                            return true;
                        else
                            return false;">Xóa</a></td>
        </tr>
        <?php
    }
    ?>
</table>

<?php
if (isset($_GET['action']) && $_GET['action'] == 'add') {
    ?>
    <form name="" action="<?php echo URL_BASE; ?>/admin/product/addSale/<?php echo $this->proId; ?>" method="post" id="cat" class="frm" enctype="multipart/form-data">
        <p>
            <label>Date Start:</label>
            <input type="text" name="txtDateStart" class="datepicker" />
        </p>
        <p>
            <label>Date End:</label>
            <input type="text" name="txtDateEnd" class="datepicker" />
        </p>
        <p>
            <label>Percent Decrease:</label>
            <input type="text" name="txtPD" id="" />
        </p>
        <p>
            <label>Content:</label>
            <input type="text" name="txtContent" id="" />
        </p>
        <p>
            <label></label>
            <input type="submit" name="btnAdd" value="Thêm" />
        </p>
    </form>
    <?php
}
?>

<?php
if (isset($_GET['action']) && $_GET['action'] == 'edit') {
    $ds = $_GET['ds'];
    $de = $_GET['de'];
    $pd = $_GET['pd'];
    $content = $_GET['content'];
    $sale_id = $_GET['sale_id'];
    ?>
    <form name="" action="<?php echo URL_BASE; ?>/admin/product/editSale/<?php echo $sale_id; ?>" method="post" id="cat" class="frm" enctype="multipart/form-data">
        <p>
            <label>Date Start:</label>
            <input type="text" name="txtDateStart" id="" value="<?php echo date('d/m/Y', strtotime($ds)); ?>" class="datepicker" />
            <input type="hidden" name="pro_id" id="" value="<?php echo $this->proId; ?>" />
        </p>
        <p>
            <label>Date End:</label>
            <input type="text" name="txtDateEnd" id="" value="<?php echo date('d/m/Y', strtotime($de)); ?>" class="datepicker" />
        </p>
        <p>
            <label>Percent Decrease:</label>
            <input type="text" name="txtPD" id="" value="<?php echo $pd; ?>" />
        </p>
        <p>
            <label>Content:</label>
            <input type="text" name="txtContent" id="" value="<?php echo $content; ?>" />
        </p>
        <p>
            <label></label>
            <input type="submit" name="btnAdd" value="Sửa" />
        </p>
    </form>
    <?php
}
?>